#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>

using namespace std; 

const int basesize = 1024;

string GetUserName()
{
    string user = getenv("USER");
    return user.empty() ? "None" : user; 
}

string GetHostName()
{
    string hostname = getenv("HOATNAME");
    return hostname.empty() ? "None" : hostname;
}

string GetPWD()
{
    string pwd = getenv("PWD");
    return pwd.empty() ? "None" : pwd; 
}

string MakeCommandLine()
{
    char command_line[basesize];
    snprintf(command_line, basesize, "[%s@%s %s]# ",\
            GetUserName().c_str(), GetHostName().c_str(),GetPWD().c_str());
    return command_line;
}

void PrintCommandLine()   // 1. 命令行提示符
{
    printf("%s",MakeCommandLine().c_str());
    fflush(stdout);
}



int main()
{
    while(true)
    {
        PrintCommandLine();   // 1. 命令行提示符
        printf("\n");
        sleep(1);
        //GetCommandLine();    // 2. 获取用户命令
        
        //AnalysisCommandLine(); // 3. 分析命令
        
        //ExecuteCommand(); // 4. 执行命令
    }
    return 0;
}




